<?php
/*
 * Author: Quan Van Sinh
 * Email: sinhvnb@vietnambiz.com
 * Update: NghiaTruong
 * Email: nghiatruong@vietnambiz.com
 * Date: 16-3-2011
 */
checkLoginHeader();
checkPermission();
$category = new category();
$category->categoryAction();
?>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/header.php'; ?>

<script type="text/javascript" src="/admin/themes/default/js/nicEdit.js"></script>
<script type="text/javascript" src="/admin/themes/default/js/category.js"></script>
<div id="wrapper">
    <div id="content" style="width: 98%;">

        <div id="categoryAction">
            <div id="box">
                <div id="rightnow">
                    <h3 class="reallynow">
                        <span>Category Actions</span>
                        <a href="javascript: closeHtml('categoryAction');">Close</a><br />
                    </h3>
                </div>
                <div id="formAddCategory">
                    <form method="post" action="/<?php echo $config ['admin_section']; ?>/category" id="form" name="formAddCategory" style="padding-top: 10px">
                        <fieldset id="fsAddCategory">
                            <legend>Add category</legend>
                            <label for="categoryname">Category name : </label>
                            <input style="width: 200px" type="text" tabindex="1" id="categoryname" name="categoryname"/>
                            <input type="hidden" id="categoryActionType" name="categoryActionType" value="addCategory"/>
                            <br>
                            <label for="parent_id">Parent : </label>
                            <select name="parent_id" id="parent_id">
                                <option selected="selected" label="none" value="0">Root</option>
                                <?php
                                $category = $category->get_cat_tree(0);
                                foreach ($category as $k => $rs) {
                                ?>
                                    <option id="article_category_id<?php echo $rs['id']; ?>" value="<?php echo $rs['id']; ?>"><? echo $rs['name']; ?></option>
                                <?php
                                }
                                ?>
                            </select>
                            <br>
                            <label>&nbsp;</label>
                            <input type="checkbox" name="cat_menu" value="1" /> Show in main menu
                            <br>
                            <label>&nbsp;</label>
                            <input type="checkbox" name="cat_typical" value="1" /> Show in homepage
                            <br>
                            <label>&nbsp;</label>
                            <input type="checkbox" name="cat_active" value="1" /> Active
                        </fieldset>


                        <fieldset id="fsAddRelationBox">
                            <legend>Relation box</legend>
                            <div>
                                <label for="categoryId">View type:</label>
                                <input type="radio" name="view_type" value="article" checked="checked" /> Article &nbsp;&nbsp;
                                <input type="radio" name="view_type" value="html"/>Html
                            </div>
                            <label>Box title:</label>
                            <input style="width: 200px; border-color: green;" type="text" id="box_title" name="box_title"/>
                            <br/>
                            <label for="rbActive">Active:</label>
                            <select id="rbActive"  name="rbActive" style="width:236px;">
                                <option value="1">Yes</option>
                                <option value="0">No</option>
                            </select>
                            <div id="divRelateBoxHtml" style="display: none">
                                <div style="padding-left: 110px;">
                                    <textarea id="rbHtml" name="value_html" rows="4" cols="40" style="width:300px;"></textarea>
                                </div>
                            </div>
                            <div id="divRelateBoxArticle">
                                <label for="searchKeyword">Keyword : </label>
                                <input style="width: 228px" type="text" id="rbKeyword"/>
                                <input type="button" value="Search" id="rbSearchArticleSubmit"/>
                                <br>
                                <label for="date">Date : </label>
                                <input style="width: 100px" type="text" id="dateFrom" name="dateFrom" onclick="javascript: NewCssCal('dateFrom','yyyymmdd','arrow')"/>
                                To
                                <input style="width: 100px" type="text" id="dateTo" name="dateTo" onclick="javascript: NewCssCal('dateTo','yyyymmdd','arrow')"/>
                                <br>
                                <label for="categoryId">Category : </label>
                                <select id="rbCategoryId" name="categoryId" style="width:236px;">
                                    <option value="">Select category</option>
                                    <?php
                                    foreach ($category as $k => $rs) {
                                        echo '<option value="' . $rs['id'] . '">' . $rs['name'] . '</option>';
                                    }
                                    ?>
                                </select>
                                <br>
                                <div>
                                    <div style="float: left">
                                        <label for="categoryId">&nbsp;</label>
                                        <select id="rbSearchArticleResult" style="width:300px;height: 200px;" multiple></select>
                                    </div>
                                    <div style="float: left">
                                        <input type="button" value="    Select    " id="rbSelectArticle" style="margin: 70px 5px 0 10px;"/><br/>
                                        <input type="button" value="    Remove    " id="rbRemoveArticle" style="margin: 10px 5px 0 5px;"/>
                                    </div>
                                    <div style="float: left">
                                        <select id="rbSearchArticleSelect" name="articleSelect[]" style="width:300px;height: 200px;border-color: green;" multiple></select>
                                    </div>
                                </div>
                            </div>
                        </fieldset>

                        <div align="center">
                            <input type="button" value="Create category" name="addCategorySubmit" id="addCategorySubmit"/>
                            <input type="reset" id="AddCategoryReset"/>
                        </div>
                    </form>
                </div>

                <div id="formEditCategory">
                    <form method="post" action="/<?php echo $config ['admin_section']; ?>/category" id="form" name="formEditCategory">
                        <fieldset id="fsEditCategory">
                            <legend>Edit category</legend>
                            <label for="name">Category name : </label>
                            <input style="width: 200px" type="text" tabindex="1" id="edCategoryname" name="edCategoryname"/>
                            <input type="hidden" id="edId" name="edId"/>
                            <input type="hidden" id="categoryActionType" name="categoryActionType" value="updateCategory"/>
                            <br/>
                            <label for="edParent_id">Parent : </label>
                            <select name="edParent_id" id="edParent_id">
                                <option selected="selected" label="none" value="0">Root</option>
                                <?php
                                    //$category = get_cat_tree(0);
                                    foreach ($category as $k => $rs) {
                                ?>
                                        <option value="<?php echo $rs['id']; ?>"><? echo $rs['name']; ?></option>
                                <?php
                                    }
                                ?>
                                </select>
                                <br>
                                <label for="parent_id">&nbsp;</label>
                                <input type="checkbox" id="edCatMenu" name="edCatMenu" value="1" /> Show in main menu
                                <br>
                                <label for="parent_id">&nbsp;</label>
                                <input type="checkbox" id="edCatTypical" name="edCatTypical" value="1" /> Show in homepage
                                <br>
                                <label for="parent_id">&nbsp;</label>
                                <input type="checkbox" id="edCatActive" name="edCatActive" value="1" /> Active

                            </fieldset>

                            <fieldset id="fsEditRelationBox">
                                <legend>Relation box</legend>
                                <div>
                                    <label for="categoryId">View type:</label>
                                    <input type="radio" id="rbEditViewTypeArticle" name="edit_view_type" value="article" checked="checked" /> Article &nbsp;&nbsp;
                                    <input type="radio" id="rbEditViewTypeHtml" name="edit_view_type" value="html"/>Html
                                </div>
                                <label>Box title:</label>
                                <input style="width: 200px; border-color: green;" type="text" id="edit_box_title" name="box_title"/>
                                <input type="hidden" id="rbId" name="rbId"/>
                                <br/>
                                <label>Active:</label>
                                <select id="rbEditActive" name="rbActive" style="width:236px;">
                                    <option value="1">Yes</option>
                                    <option value="0">No</option>
                                </select>
                                <div id="divEditRelateBoxHtml" style="display: none">
                                    <div style="padding-left: 110px;">
                                        <textarea id="rbEditHtml" name="value_html" rows="4" cols="40" style="width:300px;"></textarea>
                                    </div>
                                </div>
                                <div id="divEditRelateBoxArticle">
                                    <label for="searchKeyword">Keyword : </label>
                                    <input style="width: 228px" type="text" id="rbEditKeyword"/>
                                    <input type="button" value="Search" id="rbEditSearchArticleSubmit"/>
                                    <br>
                                    <label for="date">Date : </label>
                                    <input style="width: 100px" type="text" id="editDateFrom" name="dateFrom" onclick="javascript: NewCssCal('editDateFrom','yyyymmdd','arrow')"/>
                                    To
                                    <input style="width: 100px" type="text" id="editDateTo" name="dateTo" onclick="javascript: NewCssCal('editDateTo','yyyymmdd','arrow')"/>
                                    <br>
                                    <label for="categoryId">Category : </label>
                                    <select id="rbEditCategoryId" name="categoryId" style="width:236px;">
                                        <option value="">Select category</option>
                                    <?php
                                    foreach ($category as $k => $rs) {
                                        echo '<option value="' . $rs['id'] . '">' . $rs['name'] . '</option>';
                                    }
                                    ?>
                                </select>
                                <br>
                                <div>
                                    <div style="float: left">
                                        <label for="categoryId">&nbsp;</label>
                                        <select id="rbEditSearchArticleResult" style="width:300px;height: 200px;" multiple></select>
                                    </div>
                                    <div style="float: left">
                                        <input type="button" value="    Select    " id="rbEditSelectArticle" style="margin: 70px 5px 0 10px;"/><br/>
                                        <input type="button" value="    Remove    " id="rbEditRemoveArticle" style="margin: 10px 5px 0 5px;"/>
                                    </div>
                                    <div style="float: left">
                                        <select id="rbEditSearchArticleSelect" name="articleSelect[]" style="width:300px;height: 200px;border-color: green;" multiple></select>
                                    </div>
                                </div>
                            </div>
                        </fieldset>

                        <div align="center">
                            <input type="button" value="Update category infomation" name="editCategorySubmit" id="editCategorySubmit"/>
                        </div>
                    </form>
                </div>
            </div>
            <div style="height:10px"></div>
        </div>


        <div id="rightnow">
            <h3 class="reallynow">
                <span>Article Category</span>
                <span style="float: right"><a class="add" href="javascript: addCategory();">Add category</a></span>
                <br />
            </h3>
            <div class="youhave">
                <div id="rsMessages" style="text-align: center; color: red; font-weight: bolder"><?
                                    if (isset($_SESSION['rsMessages'])) {
                                        echo $_SESSION['rsMessages'];
                                        $_SESSION['rsMessages'] = '';
                                    }
                                    ?></div>
                                <table width="100%">

                                    <tbody>
                                        <tr>
                                            <td width="40px">&nbsp;</td>
                                            <td><b>Category name</b></td>
                                            <td width="40px" style="text-align: center"><b>Menu</b></td>
                                            <td width="40px" style="text-align: center"><b>Homepage</b></td>
                                            <td width="40px" style="text-align: center"><b>Active</b></td>
                                            <td width="100px" style="text-align: center"><b>Action</b></td>
                                        </tr>
                        <?php
                                    //$category = get_cat_tree(0);
                                    $i = 0;
                                    foreach ($category as $k => $rs) {
                                        $i++;
                        ?>

                                        <tr class="listItem">
                                            <td class="a-center"><?php echo $i; ?></td>
                                            <td>
                                                &nbsp;&nbsp;<a href="/<?php echo $config ['admin_section']; ?>/article&articleActionType=searchArticle&categoryId=<?php echo $rs['id']; ?>&searchArticleSubmit=Search"><?php echo $rs['name']; ?></a>
                                            </td>
                                            <td style="text-align: center; cursor: pointer;" onclick="toggleMenu(<?php echo $rs['id']; ?>,this);" title="Click to toggle menu"><?php echo ($rs['cat_menu'] == 1 ? 'Yes' : '--'); ?></td>
                                    <td style="text-align: center; cursor: pointer;" onclick="toggleTypical(<?php echo $rs['id']; ?>,this);" title="Click to toggle typical"><?php echo ($rs['cat_typical'] == 1 ? 'Yes' : '--'); ?></td>
                                    <td style="text-align: center; cursor: pointer;" onclick="toggleActive(<?php echo $rs['id']; ?>,this);" title="Click to toggle active"><?php echo ($rs['cat_active'] == 1 ? 'Yes' : '--'); ?></td>
                                    <td>
                                        <a href="/<?php echo $config ['admin_section']; ?>/category?categoryActionType=order_up&id=<?php echo $rs['id']; ?>"><img height="16" width="16" title="Order up" src="<?php echo $config ['admin_images_url']; ?>/up.gif"/></a>
                                        &nbsp;
                                        <a href="/<?php echo $config ['admin_section']; ?>/category?categoryActionType=order_down&id=<?php echo $rs['id']; ?>"><img height="16" width="16" title="Order down" src="<?php echo $config ['admin_images_url']; ?>/down.gif"/></a>
                                        &nbsp;
                                        <a href="javascript: editCategory('<?php echo $rs['id']; ?>');"><img height="16" width="16" title="Edit category" src="<?php echo $config ['admin_images_url']; ?>/icons/page_white_edit.png"/></a>
                                        &nbsp;
                                        <a href="javascript: deleteCategory('<?php echo $rs['id']; ?>','<?php echo $rs['name']; ?>');"><img height="16" width="16" title="Delete category" src="<? echo $config ['admin_images_url']; ?>/icons/page_white_delete.png"/></a>
                                    </td>
                                </tr>

                        <?php
                                    }
                        ?>


                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>


            </div>
<?php include_once $config ['admin_theme_path'] . $config ['admin_theme'] . '/footer.php'; ?>